<?php

use JetBrains\PhpStorm\ArrayShape;

/**
 * 统一接口返回
 * @param array $data
 * @param int $code
 * @param string $msg
 * @return array
 * @author lzx
 * @time 2021/6/16 18:56
 */
#[ArrayShape(['code' => "int", 'data' => "array", 'msg' => "string"])]
function outPut(array $data, int $code = 0, string $msg = 'success'): array
{
    return [
        'code' => $code,
        'data' => $data,
        'msg' => $msg
    ];
}

/**
 * 获取表结构
 * @param $table
 * @return array
 * @author lzx
 * @time 2021/6/27 19:57
 */
function getColumns($table): array
{
    $sql = "SHOW FULL COLUMNS FROM `$table`;";
    return \Illuminate\Support\Facades\DB::select($sql);
}

/**
 * 二维数组搜索
 * @param $array
 * @param $key
 * @param $value
 * @return array
 * @author lzx
 * @time 2021/6/27 20:16
 */
function arraySearch($array, $key, $value) :array
{
    return collect($array)->where($key,'=',$value)->toArray();
}
